<?php
/**
 * Created by PhpStorm.
 * User: Vlad
 * Date: 1/11/14
 * Time: 7:36 PM
 */

class RecentGames
{
    public static function GetRecentGames()
    {
        $stmt = DB::Query(" select
                                        o1.Name as GuessedObject,
                                        g.GuessedRank as GuessedRank,
                                        g.CertaintyPercentage as CertaintyPercentage,
                                        o2.Name as PlayedObject,
                                        o2.TimesPlayed as TimesPlayed
                            from
                                        Games as g
                            inner join
                                        Objects as o1 on o1.ObjectID = g.GuessedObject
                            inner join
                                        Objects as o2 on o2.ObjectID = g.PlayedObject
                            order by
                                        LastActivity desc
                            limit
                                        10");

        while ($row = $stmt->fetch_assoc())
        {
            $ret[] = array(
                'GuessedObject'         =>  $row['GuessedObject'],
                'GuessedRank'           =>  $row['GuessedRank'],
                'CertaintyPercentage'   =>  $row['CertaintyPercentage'],
                'PlayedObject'          =>  $row['PlayedObject'],
                'TimesPlayed'           =>  $row['TimesPlayed']
            );
        }

        $stmt->close();

        return $ret;
    }
} 